package com.ourfox.erp.servlet.handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
import com.ourfox.erp.exception.PortalException;

public class ERPMappingExceptionResolver extends SimpleMappingExceptionResolver {

	private static final Log LOGGER = LogFactory
			.getLog(ERPMappingExceptionResolver.class);

	@Override
	protected ModelAndView doResolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {

		int exceptionCode = 20000;
		if (ex instanceof PortalException) {
			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug(ex);
			}
			exceptionCode = ((PortalException) ex).getExceptionCode();
		}

		response.setStatus(exceptionCode);

		return super.doResolveException(request, response, handler, ex);
	}

}
